import { Tabs} from 'antd'
import React, { useState, useRef } from 'react'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table'
import { connect, Link } from 'umi'
import { queryProcessed, updateCorrectionInfo } from '../service'
import { BPMStatusEnum } from '@/utils/constant'
import moment from 'moment'

const { TabPane } = Tabs;

const TableList = () => {
  const actionRef = useRef();
  const actionRef2 = useRef();
  const [tabIndex, setTabIndex] = useState('0');
  const notColumns = [
    {
      title: '工号',
      dataIndex: 'code',
      hideInSearch: true,
    },
    {
      title: '姓名',
      dataIndex: 'name',
      render: (item, record) => (
        <Link to={`/info/details/${record.oid}`}>{item}</Link>
      ),
    },
    {
      title: '公司',
      dataIndex: 'orgname',

    },
    {
      title: '部门',
      dataIndex: 'unitname',
    },
    {
      title: '岗位',
      dataIndex: 'jobname',
    },
    {
      title: '职级',
      dataIndex: 'jobLevel',
      hideInSearch: true,
    },
    {
      title: '提醒状态',
      dataIndex: 'isRegularRemind',
      hideInSearch: true,
      valueEnum: {
        0: { text: '未提醒', status: 'Default' },
        1: { text: '已提醒', status: 'Success' },
      },
    },
    {
      title: '审批状态',
      dataIndex: 'regularBpmStatus',
      hideInSearch: true,
      valueEnum: BPMStatusEnum,
    },
    {
      title: '入职日期',
      dataIndex: 'hiredate',
      render: (text) => {
        return text ? moment(text).format('YYYY-MM-DD') : ''
      },
      hideInSearch: true,
    },
    {
      title: (tabIndex === '0') ? '预计转正日期' : '转正日期',
      dataIndex: 'regularDay',
      render: (text) => {
        return text ? moment(text).format('YYYY-MM-DD') : ''
      },
      hideInSearch: true,
    },
  ];

  const changeTab = (key) => {
    setTabIndex(key)
    if (key === '0') {
      actionRef.current && actionRef.current.reload()
    } else {
      actionRef2.current && actionRef2.current.reload()
    }
  }

  return (
    <PageHeaderWrapper>
      <Tabs animated={false} defaultActiveKey="0" onChange={changeTab}>
        <TabPane tab="未完成" key="0">
          <ProTable
            actionRef={actionRef}
            rowKey="oid"
            request={(params) => queryProcessed(params, tabIndex,[0,1],true,[0,2])}
            columns={notColumns}
          />
        </TabPane>
        <TabPane tab="已完成" key="1">
          <ProTable
            actionRef={actionRef2}
            rowKey="oid"
            request={(params) => queryProcessed(params, tabIndex,[2],false,[1,3])}
            columns={notColumns}
          />
        </TabPane>
      </Tabs>
    </PageHeaderWrapper>
  )
}

export default connect(({}) => ({}))(TableList)
